import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.*;

/**
 * Author: Daniel Michalski
 * Date: 05.04.13
 */

public class MappedChannelRead {

    public static final String FILE_NAME = "test.txt";

    public static void main(String[] args) {
        try ( FileChannel fChan =
                      (FileChannel) Files.newByteChannel(Paths.get(FILE_NAME)))
        {
            long size = fChan.size();
            MappedByteBuffer mBuff= fChan.map(FileChannel.MapMode.READ_WRITE, 0, size);

            for (int i = 0; i < size; i++)
                System.out.print((char) mBuff.get());
            System.out.println();
        } catch (InvalidPathException e) {
            System.out.println("Błąd ścieżki: " + e);
        } catch (IOException e) {
            System.out.println("Błąd wejścia wyjścia: " + e);
        }

    }
}
